package com.shangcheng.server.controller;

import com.shangcheng.model.domain.SmsFlashPromotionSession;
import com.shangcheng.model.vo.SmsFlashPromotionSessionVo;
import com.shangcheng.model.vo.result.Result;
import com.shangcheng.server.service.SmsFlashPromotionSessionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 场次
 */
@RestController
@RequestMapping("flashSession")
public class SmsFlashPromotionSessionController {

    @Autowired
    private SmsFlashPromotionSessionService smsFlashPromotionSessionService;

    /**
     * 添加场次
     *
     * @param smsFlashPromotionSession
     * @return
     */
    @PostMapping("create")
    public Result create(@RequestBody SmsFlashPromotionSession smsFlashPromotionSession) {
        smsFlashPromotionSessionService.create(smsFlashPromotionSession);
        return new Result(200, null, "添加成功");
    }

    /**
     * 删除场次
     *
     * @param id
     * @return
     */
    @PostMapping("delete/{id}")
    public Result delete(@PathVariable("id") Integer id) {
        smsFlashPromotionSessionService.delete(id);
        return new Result(200, null, "删除成功");
    }

    /**
     * 查询全部场次
     *
     * @return
     */
    @GetMapping("list")
    public Result SmsFlashPromotionSessionlist() {
        List<SmsFlashPromotionSession> list = smsFlashPromotionSessionService.findList();
        return new Result(200, list, "");
    }

    /**
     * 获取全部可选场次及其数量
     *
     * @return
     */
    @GetMapping("selectList")
    public Result findAllSmsFlashPromotionSessionlistByCondition(Integer flashPromotionId) {
        List<SmsFlashPromotionSessionVo> vos = smsFlashPromotionSessionService.selectList(flashPromotionId);
        return new Result(200, vos, "");
    }

    /**
     * 修改上下线状态
     *
     * @param id
     * @param status
     * @return
     */
    @PostMapping("update/status/{id}")
    //@CacheEvict(value = "SmsFlashPromotionSessionList", allEntries = true)
    public Result updateStatus(@PathVariable("id") Integer id, Integer status) {
        smsFlashPromotionSessionService.updateStatus(id, status);
        return new Result(200, null, "修改成功");
    }

    /**
     * 修改场次
     *
     * @param smsFlashPromotionSession
     * @return
     */
    @PostMapping("update/{id}")
    public Result update(@RequestBody SmsFlashPromotionSession smsFlashPromotionSession) {
        smsFlashPromotionSessionService.update(smsFlashPromotionSession);
        return new Result(200, null, "修改成功");
    }

    /**
     * 获取场次详情
     *
     * @param id
     * @return
     */
    @PostMapping("/{id}")
    public Result update(@PathVariable("id") Integer id) {
        SmsFlashPromotionSession smsFlashPromotionSession = smsFlashPromotionSessionService.findById(id);
        return new Result(200, smsFlashPromotionSession, "");
    }
}
